<?php
	function customers_properties() {
		global $kiwee, $_lang;
		
 		$custinfo = $kiwee->getCustInfo($_POST['custid']);
		
		echo '<input type="hidden" id="editid" value="' . $custinfo['id'] . '" >' . "\n";
		echo '<input type="hidden" id="editinternalkey" value="' . $custinfo['custid'] . '" />' . "\n";
		echo '<label style="color: white; font-size:24px; float:right; margin-right: 60px;">Customer #: ' . $custinfo['id'] . '</label><br /><br /> ' . "\n";
		echo '<label style="color: white; float:left;">Company:</label><input id="editcompanyname" type="text" value="' . $custinfo['companyname'] . '" size=20><br /><br />' . "\n";
		echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label style="color: white;">First:</label><input id="editfname" type="text" value="' . $custinfo['fname'] . '" size=20>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">Last:</label><input id="editlname" type="text" value="' . $custinfo['lname'] . '" size=20><br /><br />' . "\n";
		echo '<label style="color: white;">Address1:</label><input id="editaddr1" type="text" value="' . $custinfo['addr1'] . '" size=20>&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">Address2:</label><input id="editaddr2" type="text" value="' . $custinfo['addr2'] . '" size=20><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">City:</label><input id="editcity" type="text" value="' . $custinfo['city'] . '" size=15>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">State:</label><input id="editstate" type="text" value="' . $custinfo['state'] . '" size=15>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">Zip:</label><input id="editzip" type="text" value="' . $custinfo['zip'] . '" size=12><br /><br />&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">Phone 1:</label><input id="editphone_1" type="text" value="' . $custinfo['phone_1'] . '" size=12>&nbsp;&nbsp&nbsp;' . "\n";
		echo '<label style="color: white;">ext1:</label><input id="editext_1" type="text" value="' . $custinfo['ext_1'] . '" size=5>&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">Phone 2:</label><input id="editphone_2" type="text" value="' . $custinfo['phone_2'] . '" size=12>&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">ext2:</label><input id="editext_2" type="text" value="' . $custinfo['ext_2'] . '" size=5><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">fax:</label><input id="editfax" type="text" value="' . $custinfo['fax'] . '" size=10><br /><br />' . "\n";
		echo '<div style="border:1px; border-style:solid; border-color: #ff9933; padding: 10px; float:right; width:300px; margin-right: 90px; margin-top: 10px;" >' . "\n";
		echo '<p style="color: white; font-weight:bold; font-size:12px;">Web User Account</p>' . "\n";
		echo '&nbsp;&nbsp;<label style="color: white;">username:</label><input style="background-color: #444444; color: white;" id="editusername" type="text" value="' . $custinfo['username'] . '" size=10 readonly><br /><br />&nbsp;&nbsp;' . "\n";
		echo '<div id="passvalidatediv" style="display:none"><p style="color: red;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Passwords don\'t match</p></div>' . "\n";
		echo '<label style="color: white;">password:</label><input id="editpassword" type="password" onchange="passvalidator()" value="NOTAVALIDPASSWORD" size=12>&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">confirm:</label><input id="editpasswordconfirm" type="password" onchange="passvalidator()" value="NOTAVALIDPASSWORD" size=12><br /><br /> ' . "\n";
		echo '<label style="color: white;">Login Count:</label><input id="editlogincount" type="text" value="' . $custinfo['logincount'] . '" size=5>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">Failed Logins:</label><input id="editfailedlogincount" type="text" value="' . $custinfo['failedlogincount'] . '" size=5><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">Blocked:</label><input id="editblocked" type="text" value="' . $custinfo['blocked'] . '" size=1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . "\n";
		echo '<label style="color: white;">Blocked Until:</label><input id="editblockeduntil" type="text" value="' . $custinfo['blockeduntil'] . '" size=7><br /><br />' . "\n";
		echo '<label style="color: white; margin-left:10px;">Comments:</label><br /><textarea style="margin-left:40px;" id="editcommentsection" rows=5 cols=35>' . $custinfo['commentssection'] . '</textarea>' . "\n";
		echo '</div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />';
		echo '<div style="margin-top:90px;">';
		echo '<button id="updateform" style="hide" onclick="updateuser();">Update</button>';
		echo '<button id="closeform" onclick="hideBox();">Close</button>';
		echo '</div>';
		echo '</div>';
	}

	function customers_update() {
		global $kiwee, $_lang;

		echo $kiwee->updateCustInfo($_POST['editid'],$_POST['editinternalkey'],$_POST['companyname'],$_POST['fname'],$_POST['lname'],$_POST['addr1'],$_POST['addr2'],$_POST['city'],$_POST['state'],$_POST['zip'],$_POST['phone_1'],$_POST['phone_2'],$_POST['ext_1'],$_POST['ext_2'],$_POST['fax'],$_POST['username'],$_POST['pass'],$_POST['logincount'],$_POST['failedlogincount'],$_POST['blocked'],$_POST['blockeduntil'],$_POST['commentsection']);
	}

	function customers_gridload() {
		global $kiwee, $_lang;

		if ($_POST['custsearch']!= ""){
			$sql= 'SELECT * from ' . $kiwee->config['fpx'] . 'customers where id=' . $_POST['custsearch'];	
		}else {
			$sql= 'SELECT * from ' . $kiwee->config['fpx'] . 'customers';	
		}
	    $ds = mysql_query($sql) or die ("MYSQL: " . mysql_error());
	    $grd = new DataGrid('',$ds, $number_of_results);
	    $grd->noRecordMsg = $_lang["no_records_found"];
	    $grd->cssClass="grid";
	    $grd->columnHeaderClass="gridHeader";
	    $grd->itemClass="gridItem";
	    $grd->altItemClass="gridAltItem";
	    $grd->fields="id, lname, fname, companyname, lastorder, orderct, totalsales";
	    $grd->columns= $_lang["cust_id"]. ", " . $_lang["cust_lname"] . "," . $_lang["cust_fname"] . ", " . $_lang["cust_company"] . ", " . $_lang["cust_lastorder"] . ", " . $_lang["cust_orderct"] . ", " . $_lang["cust_totalorders"] . ", " . $_lang["cust_edit"];
	    $grd->colWidths="34,75,75,200,75,34,34,50,50";
	    $grd->colAligns="left, left, left, left, center, center, left, center";
	    $grd->colTypes=",,,,,,currency,template:<button id=\"edititem\" onclick=\"edituser([+id+])\">Edit</button>";
	    if($listmode=='1') $grd->pageSize=0;
	    if($_REQUEST['op']=='reset') $grd->pageNumber = 1;
	    echo $grd->render();
	}

	$oktxns[] = 'customers_properties';
	$oktxns[] = 'customers_update';
	$oktxns[] = 'customers_gridload';
?>
